Two Pi radians.
So the six lines will be at angles 0, 1*(2pi)/6, 2*(2pi)/6, 3*(2pi)/6, ...
private void drawStar( Graphics gr, int x, int y, int size ) { int endX, endY ; // Six lines radiating from (x,y) for ( int i = 0; i<6; i++ ) { endX = x + (int)(size*Math.cos( (2*Math.PI/6)*i )); endY = y - (int)(size*Math.sin( (2*Math.PI/6)*i )); // Note "-" gr.drawLine( x, y, endX, endY ); } }
The complete method is shown, above.
The Java trigonometric functions
are static methods of the Math
.
They use radians for their arguments.
The circle is divided into six pieces.
The constant pi is available in Java as Math.PI
.
There are two pi radians per circle.
One sixth of a circle is (2*Math.PI/6)
.
The minus sign is used in the calculation of endY
because
y
increases in value going down.
Using a "+" would also work because of symmetry.
What does (int)
do in the statement
endY = y - (int)(size*Math.sin( (2*Math.PI/6)*i ));